﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Data.OracleClient;
namespace GSLMS.DAL.Oracle
{
	/// <summary>
	/// 数据访问类:SYS_SURVEYTMPSETDETAIL
	/// </summary>
	public partial class SYS_SURVEYTMPSETDETAIL : BaseDAL<GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL>
	{
		private readonly GSLMS.Core.Loger log = new Core.Loger();
		public SYS_SURVEYTMPSETDETAIL()
		{}
		#region  Method
		/// <summary>
		///  增加一条数据
		/// </summary>
		public override bool Add(GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL model)
		{
			bool flag = false;
			OracleParameter[] parms =new OracleParameter[]{
								new OracleParameter("P_ID", model.ID),
								new OracleParameter("P_SURVEYTMPSETID", model.SURVEYTMPSETID),
								new OracleParameter("P_SURVEYNAME", model.SURVEYNAME),
								new OracleParameter("P_SORTNO", model.SORTNO),
								new OracleParameter("P_TMPITEMNAME", model.TMPITEMNAME),
								new OracleParameter("P_TMPTYPE", model.TMPTYPE)};
  
			for (int i = 0; i < 6; i++)
			{
				parms[i].Direction = ParameterDirection.Input;
			}

			try
			{
                OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_sys.proc_surveytmpsetdetail_add", parms);
				flag = true;
			}
			catch (Exception ex)
			{
				log.ExceptionHand(ex);
			}
			return flag;
		}

		/// <summary>
		///  更新一条数据
		/// </summary>
		public override bool Update(GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL model)
		{
			bool flag = false;
            //不再使用
            //OracleParameter[] parms =new OracleParameter[]{
            //                    new OracleParameter("P_ID", model.ID),
            //                    new OracleParameter("P_SURVEYTMPSETID", model.SURVEYTMPSETID),
            //                    new OracleParameter("P_SURVEYNAME", model.SURVEYNAME),
            //                    new OracleParameter("P_SORTNO", model.SORTNO),
            //                    new OracleParameter("P_TMPITEMNAME", model.TMPITEMNAME),
            //                    new OracleParameter("P_TMPTYPE", model.TMPTYPE)};
  
            //for (int i = 0; i < 6; i++)
            //{
            //    parms[i].Direction = ParameterDirection.Input;
            //}

            //try
            //{
            //    OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_sys_surveytmpsetdetail_update", parms);
            //    flag = true;
            //}
            //catch (Exception ex)
            //{
            //    log.ExceptionHand(ex);
            //}
			return flag;
		}

		/// <summary>
		///  删除一条数据
		/// </summary>
		public override bool Delete(long ID)
		{
			bool flag = false;
            //不再使用
            //OracleParameter[] parms =new OracleParameter[]{
            //                    new OracleParameter("P_ID", ID)};
  
            //    parms[0].Direction = ParameterDirection.Input;

            //try
            //{
            //    OracleHelper.ExecuteNonQuery(OracleHelper.connectionString, CommandType.StoredProcedure, "pkg_apply.proc_sys_surveytmpsetdetail_delete", parms);
            //    flag = true;
            //}
            //catch (Exception ex)
            //{
            //    log.ExceptionHand(ex);
            //}
			return flag;
		}

		/// <summary>
		///DataRowToModel 
		/// </summary>
		private GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL DataRowToModel(DataRow dr)
		{
			if (dr != null && dr.ItemArray.Length > 0)
			{
				GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL model = new GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL();
				if(dr["ID"]!=null && dr["ID"].ToString()!="")
				{
					model.ID=OracleHelper.ToLong(dr["ID"].ToString());
				}
				if(dr["SURVEYTMPSETID"]!=null && dr["SURVEYTMPSETID"].ToString()!="")
				{
					model.SURVEYTMPSETID=OracleHelper.ToLong(dr["SURVEYTMPSETID"].ToString());
				}
				if(dr["SURVEYNAME"]!=null && dr["SURVEYNAME"].ToString()!="")
				{
					model.SURVEYNAME=dr["SURVEYNAME"].ToString();
				}
				if(dr["SORTNO"]!=null && dr["SORTNO"].ToString()!="")
				{
                    model.SORTNO = OracleHelper.ToInt(dr["SORTNO"].ToString());
				}
				if(dr["TMPITEMNAME"]!=null && dr["TMPITEMNAME"].ToString()!="")
				{
					model.TMPITEMNAME=dr["TMPITEMNAME"].ToString();
				}
				if(dr["TMPTYPE"]!=null && dr["TMPTYPE"].ToString()!="")
				{
                    model.TMPTYPE = OracleHelper.ToInt(dr["TMPTYPE"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public override GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL GetByID(long ID)
		{
			GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL sModel = new GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL();
			string sql = "";
			sql = "select * from TB_SYS_SURVEYTMPSETDETAIL where id=" + ID.ToString();
			DataSet ds = OracleHelper.ExecuteDataset(sql);
			if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
			{
				sModel = DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
			return null;
			}
			return sModel;
		}

		/// <summary>
		/// 分页提取数据
		/// </summary>
		public override List<GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL> GetList(GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL searchParam)
		{
			var list=new List<GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL>();
			DataTable dt = null;
			string tblName = "TB_SYS_SURVEYTMPSETDETAIL";
			string sqlWhere="";
			string strSort="";
			int pageSize=20;
			int pageIndex=1;
			string strFields="*";
			int totalCount = 0;
			int countFlag = 1;
			dt = OracleHelper.GetPageData(tblName, strFields, strSort, pageSize, pageIndex,countFlag, sqlWhere, out totalCount);
			if (dt != null && dt.Rows.Count > 0)
			{
				for (int i = 0; i < dt.Rows.Count; i++)
				{
					GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL model = new GSLMS.Entity.TB_SYS_SURVEYTMPSETDETAIL();
					model = DataRowToModel(dt.Rows[i]);
					list.Add(model);
				}
			}
			else
			{
				return null;
			}
			return list;
		}

		#endregion  Method
	}
}

